Deterministic replay in a virtual machine creates an execution that is logically equivalent to an original execution of interest. Two executions are logically equivalent if they contain the same set of dynamic instructions, each dynamic instruction computes the same result in the two executions, and the two executions compute the same final state of the system (processor, memory and devices). Virtual machines are software abstractions of physical computer systems, generally using virtualization software which is typically a thin layer of software that logically sits and provides an interface between hardware and guest OS. Virtualization is well known to those in the field of computer science.
A virtual machine-based deterministic replayer may support full-system replay; i.e., the entire virtual machine (VM), including guest operating system (OS) and guest applications, is recorded and replayed. During recording, all sources of non-determinism from outside the virtual machine are captured and logged in a log file. These include data and timing of inputs to all devices, including virtual disks, virtual network interface cards (NIC), etc. A combination of techniques, such as device emulation and binary translation, are used to ensure deterministic replay as long as the recorded device input data are replayed at right time.
Certain central processor unit (CPU) instructions are non-deterministic. A non-deterministic instruction is one whose output is not determined entirely by its inputs or a current architectural state. For example, the x86 RDTSC instruction returns the current time expressed in processor clocks, RDPMC and RDMSR return the contents of performance counter registers, etc. As shown in FIG. 1, the outputs of non-deterministic instructions can arise from the interaction of the VM with a non-deterministic units such as real time clock 16, which is a device that can be queried by a CPU with a RDTSC instruction, whose result is returned in real-time and depends on the when the instruction is executed. Examples of other non-deterministic units include input devices (such as a keyboard, mouse, microphone, etc.) a thermal sensor, a transducer, a network card, a video camera, and so on. Such devices are non-deterministic because they produce inputs that cannot be predicted based solely on the state of the machine.
When executing an application within certain VMs, the virtualization software can record the complete execution behavior. Having saved this behavioral information, the user can replay that exact and complete behavior an unlimited number of times. This can be useful for debugging. For example, a users can record execution of the VM, and then attach a gdb debugger to the guest operating system or guest applications during replay. On replay, the user can look at memory, set breakpoints, and single step through the execution to identify problems and resolve them. Of course, record and replay have other applications, any of which may benefit from the embodiments described herein.
FIG. 1 shows one example of a virtualized computer system 10 wherein the results of non-deterministic instructions are stored in log 40 during record mode. One of applications 28 or guest operating system 24 (including drivers 26) may issue a non-deterministic instruction to virtual system hardware 22, which, as generally known, is implemented by virtualization software 30, e.g., by hypervisor 32. Guest instructions (that is, instructions issuing from VM 20) are often directly executed on host CPU 14. During direct execution of guest instructions from VM 20, the virtual memory system (not shown) and CPU 14 of host platform 12 assume a configuration associated with the context of VM 20. In the present example, VM 20 issues a non-deterministic instruction to read a timestamp value from real-time clock 16, which returns the non-deterministic value, i.e., the timestamp value. Other instructions may similarly elicit non-deterministic values as described above. When system 10 is in record mode, hypervisor 32 records the value in log 40 so that the same results may be made available during replay so that the replay behavior duplicates the behavior of the VM 20 during record mode. In order for the hypervisor to carry out the function of recording the non-deterministic value to log 40, system 10 must exit the context associated with VM 20 and enter a context associated with hypervisor 32. Similarly, when a non-deterministic instruction is executed during replay, it triggers an exit from the context of VM 20 to a context of hypervisor 32, which reads the non-deterministic value from log 40 and returns the value that was recorded for the instruction to VM 20.
Changing execution contexts from VM 20 to hypervisor 32 and back is a resource-intensive operation that can introduce substantial penalties in performance. This problem can become severe when numerous such exits are required due to the execution of many non-deterministic instructions from guest application 28 during record and replay. For example, one or more non-deterministic instructions can occur in a loop, causing a large number of non-deterministic instruction executions in a short time.